///////////////////////////////////////////////////////////
//  CloudLayer.cpp
//  Implementation of the Class CloudLayer
//  Created on:      21-sep-2007 15:40:08
///////////////////////////////////////////////////////////

#include "CloudLayer.h"
#include <iostream>

#define SIZE_PKCLOUDLAYER 10
#define SIZE_CODE 10
#define SIZE_DATE 11
#define SIZE_HEIGHT 4
#define SIZE_TYPE 7


#define SIZE_PKCLOUDLAYER_SCHEMA 13
#define SIZE_CODE_SCHEMA 9
#define SIZE_HEIGHT_SCHEMA 6
#define SIZE_TYPE_SCHEMA 4
#define SIZE_DATE_SCHEMA 4

campo CloudLayer::PK[2] = {{"PKCloudLayer",CHAR, SIZE_PKCLOUDLAYER},{0,0,0}};
campo CloudLayer::CODE[2] = {{"stationCode",CHAR, SIZE_CODE},{0,0,0}};
campo CloudLayer::CODE_SAMPLE[2] = {{"sampleCode",CHAR, SIZE_CODE},{0,0,0}};
campo CloudLayer::DATE[2] = {{"date",CHAR, SIZE_DATE},{0,0,0}};
campo CloudLayer::HEIGHT[2] = {{"height",CHAR, SIZE_HEIGHT},{0,0,0}};
campo CloudLayer::TYPE[2] = {{"type",CHAR, SIZE_TYPE},{0,0,0}};


campo CloudLayer::CLOUDLAYER_SCHEMA[SIZE_CLOUDLAYER_SCHEMA] = {{"PKCloudLayer",CHAR, SIZE_PKCLOUDLAYER}, 
										{"stationCode",CHAR, SIZE_CODE}, 
										{"sampleCode",CHAR, SIZE_CODE},
										{"date",CHAR, SIZE_DATE},
										{"height",CHAR, SIZE_HEIGHT}, 
										{"type",CHAR, SIZE_TYPE}, 
										{0,0,0}};

#ifndef UNO
	#define UNO 1
#endif

#ifndef ZERO
	#define ZERO 0
#endif

CloudLayer::CloudLayer(){

}


CloudLayer::~CloudLayer(){

}

int CloudLayer::getSchemaSize(){
	return  SIZE_CLOUDLAYER_SCHEMA;
}

void CloudLayer::setDate(std::string date){
	this->date = date;
}
std::string CloudLayer::getDate(void){
	return this->date;
} 
void CloudLayer::setStationCode(std::string code){
	this->stationCode = code;
}
std::string CloudLayer::getStationCode(void){
	return this->stationCode;
} 
void CloudLayer::setSampleCode(std::string code){
	this->sampleCode = code;
}
std::string CloudLayer::getSampleCode(void){
	return this->sampleCode;
} 
std::string CloudLayer::getValor(std::string atribName){

	if (CloudLayer::PK[0].nombre == atribName){
		return this->PKCloudLayer;
	}
	if (CloudLayer::CODE[0].nombre == atribName){
		return this->stationCode;
	}
	if (CloudLayer::HEIGHT[0].nombre == atribName){
		return this->height;
	}
	if (CloudLayer::TYPE[0].nombre == atribName){
		return this->type;
	}
	if (CloudLayer::DATE[0].nombre == atribName){
		return this->date;
	}
	return "";
}

std::string CloudLayer::getKey()
{
	return this->PKCloudLayer;
}
void CloudLayer::setKey(std::string key){
	this->PKCloudLayer = key;
}

bool CloudLayer::EsMayor(std::string atributte, Persistent *object)
{
	return (this->getValor(atributte) > object->getValor(atributte));
}


void CloudLayer::loadAtribFromNode(XMLNode* node){

	this->height = node->getAtributo("height");
	this->type = node->getAtributo("type");
	
}

void CloudLayer::setHeight(std::string ht)
{
	this->height=ht;	
}

std::string CloudLayer::getHeight(void)
{
	return this->height;	
}

void CloudLayer::setType(std::string type)
{
	this->type=type;
}

std::string CloudLayer::getType(void)
{
	return this->type;	
}

void CloudLayer::setPKCloudLayer(std::string pk)
{
	this->PKCloudLayer = pk;
}

std::string CloudLayer::getPKCloudLayer()
{
	return this->PKCloudLayer;
}


campo* CloudLayer::getSchema()
{
	return CloudLayer::CLOUDLAYER_SCHEMA;
}

campo* CloudLayer::getPrimaryKey()
{
	return CloudLayer::PK;
}

void CloudLayer::loadRegistro(void* registro)
{
	campo* esquema = NULL;

	char ptrPKCloudLayer[SIZE_PKCLOUDLAYER + UNO];
	char ptrStationCode[SIZE_CODE + UNO];
	char ptrHeight[SIZE_HEIGHT + UNO];
	char ptrType[SIZE_TYPE  + UNO];
	char ptrDate[SIZE_DATE + UNO];

	memset(ptrPKCloudLayer, ZERO, SIZE_PKCLOUDLAYER + UNO);
	memset(ptrStationCode, ZERO, SIZE_CODE + UNO);
	memset(ptrHeight, ZERO, SIZE_HEIGHT + UNO);
	memset(ptrType, ZERO, SIZE_TYPE + UNO);
	memset(ptrDate, ZERO, SIZE_DATE + UNO);

	esquema = this->getSchema();

	RecordHandler::REG_GET(registro, esquema, "PKCloudLayer, stationCode, height, type, date", ptrPKCloudLayer, ptrStationCode, ptrHeight, ptrType, ptrDate);
	
	this->PKCloudLayer.clear();
	this->PKCloudLayer += ptrPKCloudLayer;
	
	this->stationCode.clear();
	this->stationCode += ptrStationCode;
	
	this->height.clear();
	this->height += ptrHeight;

	this->type.clear();
	this->type += ptrType;
	
	this->date.clear();
	this->date += ptrDate;
}


void CloudLayer::saveInRegistro(void* registro)
{
	campo* esquema = NULL;

	char ptrPKCloudLayer[SIZE_PKCLOUDLAYER + UNO];
	char ptrStationCode[SIZE_CODE + UNO];
	char ptrHeight[SIZE_HEIGHT + UNO];
	char ptrType[SIZE_TYPE  + UNO];
	char ptrDate[SIZE_DATE + UNO];

	memset(ptrPKCloudLayer, ZERO, SIZE_PKCLOUDLAYER + UNO);
	memset(ptrStationCode, ZERO, SIZE_CODE + UNO);
	memset(ptrHeight, ZERO, SIZE_HEIGHT + UNO);
	memset(ptrType, ZERO, SIZE_TYPE + UNO);
	memset(ptrDate, ZERO, SIZE_DATE + UNO);

	strncpy(ptrPKCloudLayer, (char*)this->PKCloudLayer.c_str(), SIZE_PKCLOUDLAYER);
	strncpy(ptrStationCode, (char*)this->stationCode.c_str(), SIZE_CODE);
	strncpy(ptrHeight, (char*)this->height.c_str(), SIZE_HEIGHT );
	strncpy(ptrType, (char*)this->type.c_str(), SIZE_TYPE);
	strncpy(ptrDate, (char*)this->date.c_str(), SIZE_DATE );

	esquema = this->getSchema();

	RecordHandler::REG_SET(registro, esquema, "PKCloudLayer, stationCode, height, type, date", ptrPKCloudLayer, ptrStationCode, ptrHeight, ptrType, ptrDate);

}
	
const CloudLayer & CloudLayer::operator=(const CloudLayer& cl)
{
	PKCloudLayer = cl.PKCloudLayer;
	stationCode = cl.stationCode;
	height = cl.height;
	type = cl.type;
	date = cl.date;
	return (*this);	
}

CloudLayer::CloudLayer(const CloudLayer & cl)
{
	PKCloudLayer = cl.PKCloudLayer;
	stationCode = cl.stationCode;
	height = cl.height;
	type = cl.type;
	date = cl.date;	
}

XMLNode* CloudLayer::toViewXML()
{
	XMLNode* node = new XMLNode();
	node->setNombre("CloudLayer");
	node->insertarAtributo("stationCode",this->getStationCode());
	node->insertarAtributo("date",this->getDate());
	node->insertarAtributo("height",this->getHeight());
	node->insertarAtributo("type",this->getType());
	return node;	
}

void CloudLayer::print()
{
	std::cout << "PKCLOUDLAYER: " << PKCloudLayer << std::endl;
	std::cout << "STATIONCODE: " << stationCode << std::endl;
	std::cout << "HEIGHT: " << height << std::endl;
	std::cout << "TYPE: " << type << std::endl;
	std::cout << "DATE: " << date << std::endl;
}

